package com.orientsec.autotest.project.system.execTask.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.execTask.domain.ExecTask;
import com.orientsec.autotest.project.system.execTask.service.IExecTaskService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * 案例执行信息操作处理
 * 
 * @author autotest
 * @date 2020-02-19
 */
@Controller
@RequestMapping("/system/execTask")
public class ExecTaskController extends BaseController
{
    private String prefix = "system/execTask";
	
	@Autowired
	private IExecTaskService execTaskService;
	
	@RequiresPermissions("system:execTask:view")
	@GetMapping()
	public String execTask()
	{
	    return prefix + "/execTask";
	}
	
	/**
	 * 查询案例执行列表
	 */
	@RequiresPermissions("system:execTask:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ExecTask execTask)
	{
		startPage();
        List<ExecTask> list = execTaskService.selectExecTaskList(execTask);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出案例执行列表
	 */
	@RequiresPermissions("system:execTask:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExecTask execTask)
    {
    	List<ExecTask> list = execTaskService.selectExecTaskList(execTask);
        ExcelUtil<ExecTask> util = new ExcelUtil<ExecTask>(ExecTask.class);
        return util.exportExcel(list, "execTask");
    }
	
	/**
	 * 新增案例执行
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存案例执行
	 */
	@RequiresPermissions("system:execTask:add")
	@Log(title = "案例执行", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ExecTask execTask)
	{		
		return toAjax(execTaskService.insertExecTask(execTask));
	}

	/**
	 * 修改案例执行
	 */
	@GetMapping("/edit/{taskId}")
	public String edit(@PathVariable("taskId") Integer taskId, ModelMap mmap)
	{
		ExecTask execTask = execTaskService.selectExecTaskById(taskId);
		mmap.put("execTask", execTask);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存案例执行
	 */
	@RequiresPermissions("system:execTask:edit")
	@Log(title = "案例执行", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ExecTask execTask)
	{		
		return toAjax(execTaskService.updateExecTask(execTask));
	}
	
	/**
	 * 删除案例执行
	 */
	@RequiresPermissions("system:execTask:remove")
	@Log(title = "案例执行", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(execTaskService.deleteExecTaskByIds(ids));
	}
	
}
